package com.hjm.project.menubar.relation.controller;

import java.util.List;

import com.hjm.project.menubar.info.domain.MenubarInfo;
import com.hjm.project.menubar.info.service.IMenubarInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.menubar.relation.domain.MenubarGl;
import com.hjm.project.menubar.relation.service.IMenubarGlService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 功能关联信息Controller
 * 
 * @author LOVE
 * @date 2020-11-26
 */
@Controller
@RequestMapping("/menubar/relation")
public class MenubarGlController extends BaseController
{
    private String prefix = "menubar/relation";

    @Autowired
    private IMenubarGlService menubarGlService;

    @Autowired
    private IMenubarInfoService menubarInfoService;

    @RequiresPermissions("menubar:relation:view")
    @GetMapping()
    public String relation()
    {
        return prefix + "/relation";
    }

    /**
     * 查询功能关联信息列表
     */
    @RequiresPermissions("menubar:relation:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MenubarGl menubarGl)
    {
        startPage();
        List<MenubarGl> list = menubarGlService.selectMenubarGlList(menubarGl);
        return getDataTable(list);
    }

    /**
     * 导出功能关联信息列表
     */
    @RequiresPermissions("menubar:relation:export")
    @Log(title = "功能关联信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MenubarGl menubarGl)
    {
        List<MenubarGl> list = menubarGlService.selectMenubarGlList(menubarGl);
        ExcelUtil<MenubarGl> util = new ExcelUtil<MenubarGl>(MenubarGl.class);
        return util.exportExcel(list, "relation");
    }

    /**
     * 新增功能关联信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存功能关联信息
     */
    @RequiresPermissions("menubar:relation:add")
    @Log(title = "功能关联信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MenubarGl menubarGl)
    {

        return toAjax(menubarGlService.insertMenubarGl(menubarGl));
    }

    /**
     * 修改功能关联信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MenubarGl menubarGl = menubarGlService.selectMenubarGlById(id);
        mmap.put("menubarGl", menubarGl);
        return prefix + "/edit";
    }

    /**
     * 修改保存功能关联信息
     */
    @RequiresPermissions("menubar:relation:edit")
    @Log(title = "功能关联信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MenubarGl menubarGl)
    {
        return toAjax(menubarGlService.updateMenubarGl(menubarGl));
    }

    /**
     * 删除功能关联信息
     */
    @RequiresPermissions("menubar:relation:remove")
    @Log(title = "功能关联信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(menubarGlService.deleteMenubarGlByIds(ids));
    }

    @GetMapping("/selectMenubar")
    public String selectMenubar()
    {
        return prefix + "/selectMenubar";
    }

    /**
     * 查询首页功能信息列表
     */
    @PostMapping("/selectMenubarList")
    @ResponseBody
    public TableDataInfo list(MenubarInfo menubarInfo)
    {
        startPage();
        List<MenubarInfo> list = menubarInfoService.selectMenubarInfoList(menubarInfo);
        return getDataTable(list);
    }
}
